<?php


namespace app\Shop\controller;

use app\common\JwtUtil;
use app\model\Shop;
use app\model\Shoplogin;


##商户登录
class Login {
	static function index() {
		$input = input('post.');
		if (empty($input['account']) || empty($input['password'])) {
			return json(['status' => false, 'msg' => '不能为空']);
		}
		$account = Shoplogin::where(['account' => $input['account']])->select();
		if (count($account) == 0) {
			return json(['status' => false, 'msg' => '账号不存在']);
		}
		$user = Shop::where(['Shoplogin_id' => $account['0']['id']])->select();
		if ($account['0']['password'] != $input['password']) {
			return json(['status' => false, 'msg' => '密码错误']);
		}
		if ($user['0']['apply_state'] == 'false') {
			return json(['status' => false, 'msg' => '账号申请未通过']);
		}
		$token = JwtUtil::encode($input);
		\session('identity', $user['0']['identity']);
		return json(['status' => true, 'token' => $token, 'type' => false, 'user' => $user, 'account' => $account['0']['account']]);
	}
}